package com.gateway.handler;

/**
 * @author xiangminwen
 * @date 2025/2/20 15:43
 */
public class Result<T> {
    private T data;
    private String code;
    private boolean result;
    private String message;
    private String traceId;


    public Result(String code, String message, boolean result) {
        this.code = code;
        this.message = message;
        this.result = result;
    }

    public Result(String code, String message, T data, boolean result) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.result = result;
    }

    public static <T> Result<T> success() {
        return new Result("0", "成功", true);
    }

    public static <T> Result<T> success(T data, String msg) {
        return new Result("0", msg, data, true);
    }

    public static <T> Result<T> success(T data, boolean res) {
        return new Result("0", "成功", data, res);
    }

    public static <T> Result<T> success(T data) {
        return new Result("0", "成功", data, true);
    }

    public static <T> Result<T> success(String msg) {
        return new Result("0", msg, true);
    }

    public static <T> Result<T> failure() {
        return new Result("-1", "系统异常", false);
    }

    public static <T> Result<T> failure(String msg) {
        return new Result("-1", msg, false);
    }

    public static <T> Result<T> failure(String code, String msg) {
        return new Result(code, msg, false);
    }

    public boolean isResult() {
        return this.result;
    }

    public void setResult(boolean result) {
        this.result = result;
    }

    public String getCode() {
        return this.code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return this.message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getTraceId() {
        return this.traceId;
    }

    public void setTraceId(String traceId) {
        this.traceId = traceId;
    }

    public T getData() {
        return this.data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String toString() {
        StringBuilder str = new StringBuilder("Result{");
        str.append("result=").append(this.result);
        str.append(", code='").append(this.code).append('\'');
        str.append(", message='").append(this.message).append('\'');
        str.append(", traceId='").append(this.traceId).append('\'');
        str.append(", data=").append(this.data);
        str.append('}');
        return str.toString();
    }
}
